package com.atguigu.spzx.manager.controller;

import com.atguigu.spzx.manager.service.SysUserService;
import com.atguigu.spzx.model.dto.system.SysUserDto;
import com.atguigu.spzx.model.entity.system.SysUser;
import com.atguigu.spzx.model.vo.common.Result;
import com.atguigu.spzx.model.vo.common.ResultCodeEnum;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * ClassName: SysUserController
 * Package: com.atguigu.spzx.manager.controller
 * Description:
 *
 * @Author 刘强
 * @Create 2024/7/2 9:50
 * @Version 1.0
 */
@RestController
@RequestMapping("/admin/system/sysUser")
public class SysUserController {
    @Resource
    private SysUserService sysUserService;

    /**
     * 根据id删除用户
     * @param sysUserId
     * @return
     */
    @DeleteMapping("deleteById/{sysUserId}")
    public Result deleteById(@PathVariable Long sysUserId){
        sysUserService.deleteById(sysUserId);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }

    /**
     * 修改用户信息
     * @param sysUser
     * @return
     */
    @PutMapping("/updateSysUser")
    public Result updateSysUser(@RequestBody SysUser sysUser){
        sysUserService.updateSysUser(sysUser);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }

    /**
     * 新增系统用户
     * @param sysUser
     * @return
     */
    @PostMapping("/saveSysUser")
    public Result saveSysUser(@RequestBody SysUser sysUser){
        sysUserService.saveSysUser(sysUser);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }
    /**
     * 分页带条件模糊查询
     */
    @GetMapping("/findByPage/{pageNum}/{pageSize}")
    public Result findByPage(SysUserDto sysUserDto,
                             @PathVariable Integer pageNum,
                             @PathVariable Integer pageSize){
        PageInfo<SysUser> page = sysUserService.findByPage(sysUserDto,pageNum,pageSize);
        return Result.build(page, ResultCodeEnum.SUCCESS);
    }

}
